/**
 * 
 */
package com.yst.metho.web.application.components.table;

import nextapp.echo2.app.Button;
import nextapp.echo2.app.Component;
import nextapp.echo2.app.Table;
import nextapp.echo2.app.event.ActionEvent;
import nextapp.echo2.app.event.ActionListener;
import nextapp.echo2.app.table.TableCellRenderer;

import com.yst.metho.web.application.interfaces.IListingViewModel;

/**
 * @author perso
 * 
 */
public class SortableTableHeaderCellRenderer implements TableCellRenderer
{

	/*
	 * (non-Javadoc)
	 * 
	 * @see nextapp.echo2.app.table.TableCellRenderer#getTableCellRendererComponent(nextapp.echo2.app.Table,
	 *      java.lang.Object, int, int)
	 */
	public Component getTableCellRendererComponent(final Table table, Object value, final int column, int row)
	{
		Button lbl = new Button();
		lbl.setText(value.toString());
		lbl.setStyleName("ListingView.HeaderLabel");
		lbl.addActionListener(new ActionListener()
		{
			/*
			 * (non-Javadoc)
			 * 
			 * @see nextapp.echo2.app.event.ActionListener#actionPerformed(nextapp.echo2.app.event.ActionEvent)
			 */
			public void actionPerformed(ActionEvent e)
			{
				IListingViewModel model = (IListingViewModel) table.getModel();
				model.setSortableColumn(column);
				model.sort();
			}
		});
		return lbl;
	}

}
